<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<%@page import="javax.naming.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>数据查询</title>
<style>
td{background-color: #FFF; font-size:12px; min-width:150px;}
th{background-color: #DDD; font-size:12px; min-width:150px;}
</style>
</head>
<body>
<table cellpadding="1" cellspacing="1" style="background-color: #CCC;">
	<%
		javax.naming.Context initCtx = new javax.naming.InitialContext();
	 	Context envContext = (Context) initCtx.lookup("java:/comp/env");


		javax.sql.DataSource datasource = (javax.sql.DataSource) envContext.lookup("jdbc/AppDs");

		java.sql.Connection conn = datasource.getConnection();

		java.sql.ResultSet rs = null;

		java.sql.PreparedStatement pstmt = null;

		String type = request.getParameter("type");
		String data = request.getParameter("data");
		String mobile = request.getParameter("mobile");

		if ("redemptionCode".equals(type)) {
			String sql ="SELECT " +
					" b.PACKAGE_NUMBER " +
					" ,a.SHORT_NAME " +
					" ,a.ACTIVATION_CODE " +
					" ,b.ACTIVE_MEMBER_ID " +
					" ,c.MEMBER_NAME " +
					" ,c.MOBILE_PHONE " +
					" ,d.car_plate " +
					" ,c.DEALER_ID  " +
					" FROM " +
					" tm_member_package_redemption a, " +
					" tm_member_package_info b, " +
					"  tm_raw_member c, " +
					"  tm_raw_car_plate d " +
					" WHERE " +
					" a.PACKAGE_ID = b.id " +
					" and c.ID = b.ACTIVE_MEMBER_ID " +
					" and d.id = b.ACTIVE_CAR_ID " +
					" AND b.PACKAGE_NUMBER = ? ";

			try {
				pstmt = conn.prepareStatement(sql);

				pstmt.setString(1, data);

				rs = pstmt.executeQuery();
				
				%>
				
				<tr>
					<th>卡号</th>
					<th>套餐名</th>
					<th>抵扣码</th>
					<th>激活会员id</th>
					<th>激活会员名称</th>
					<th>手机号</th>
					<th>车牌号</th>
					<th>门店号</th>
				</tr>
				<% 
				while (rs.next()) {
					%>
					<tr>
						<td><%=rs.getObject(1) %></td>
						<td><%=rs.getObject(2) %></td>
						<td><%=rs.getObject(3) %></td>
						<td><%=rs.getObject(4) %></td>
						<td><%=rs.getObject(5) %></td>
						<td><%=rs.getObject(6) %></td>
						<td><%=rs.getObject(7) %></td>
						<td><%=rs.getObject(8) %></td>
					</tr>
					<% 
				}

			} catch (SQLException e) {

			} finally {
				if (rs != null) {
					try {
						rs.close();
					} catch (SQLException e) {
						rs = null;
					}
				}
				
				if (pstmt != null) {
					try {
						pstmt.close();
					} catch (SQLException e) {
						pstmt = null;
					}
				}

				

			}
			
			
			%>
			</table>
			<br/>
			
			<table cellpadding="1" cellspacing="1" style="background-color: #CCC;">
			<%
			
			
			String sqlSMS = "select CONTENT, DEST_MOBILE, CREATE_DATE, SCHEDULED_SEND_TIME, HAS_SENT from tt_common_sms_content where DEST_MOBILE = ? order by CREATE_DATE desc ";

			try {
				pstmt = conn.prepareStatement(sqlSMS);

				pstmt.setString(1, mobile);

				rs = pstmt.executeQuery();
				
				%>
				
				<tr>
					<th>短信内容</th>
					<th>手机号码</th>
					<th>创建时间</th>
					<th>任务发送时间</th>
					<th>发送状态（ 0  否 1 是）</th>
				</tr>
				<% 
				while (rs.next()) {
					%>
					<tr>
						<td><%=rs.getObject(1) %></td>
						<td><%=rs.getObject(2) %></td>
						<td><%=rs.getObject(3) %></td>
						<td><%=rs.getObject(4) %></td>
						<td><%=rs.getObject(5) %></td>
					</tr>
					<% 
				}

			} catch (SQLException e) {

			} finally {
				if (rs != null) {
					try {
						rs.close();
					} catch (SQLException e) {
						rs = null;
					}
				}
				

				if (pstmt != null) {
					try {
						pstmt.close();
					} catch (SQLException e) {
						pstmt = null;
					}
				}


				if (conn != null) {
					try {
						conn.close();
					} catch (SQLException e) {
						conn = null;
					}
				}

			}
			

		} else if ("activeCode".equals(type)) {

		}
	%>
</table>

</body>
</html>